//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    _index:null,
  },
  
  onReady: function (e) {
    // 使用 wx.createAudioContext 获取 audio 上下文 context
    this.audioCtx = wx.createAudioContext('myAudio')
  },
  //选择音乐
  chooseMusic: function (event) {
    //添加索引 更改选中音乐的样式
    this.setData({
      _index: event.currentTarget.dataset.index,
    })
    //播放音乐
    var url = event.currentTarget.dataset.url;  
    this.audioCtx.setSrc(url)
    this.audioCtx.play();
  },

  onLoad: function () {
    var that = this;
    //请求图片
    wx.request({
      url: 'https://cai.shisongyan.top/image',
      success: function (res) {
        if(res.data.status==1001){
          that.setData({
            imgUrls: res.data.list,
          })
        }
      }
    }) 
    //请求音乐列表
    wx.request({
      url: 'https://cai.shisongyan.top/music',
      success: function (res) {
        if (res.data.status == 1001) {
          that.setData({
            musicUrls: res.data.list,
          })
        }
      }
    })  
  },
  
})
